package com.backend.service.Impl;

import com.backend.common.AddAction;
import com.backend.common.AssAdminUpdateInfor;
import com.backend.common.GetAssActionCond;
import com.backend.config.Result;
import com.backend.mapper.AssAdminMapper;
import com.backend.service.AssAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AssAdminServiceImpl implements AssAdminService {

    @Autowired
    AssAdminMapper assAdminMapper;


    @Override
    public Map<String, String> getAssNameById(String assId) {
        return assAdminMapper.getAssNameById(assId);
    }

    @Override
    public Result getAssById(String assId) {
        Map<String,String> map=assAdminMapper.getAssById(assId);
        return Result.success("查找成功",map);
    }

    @Override
    public Result addAssActionByAssId(AddAction addAction) {

        List<Map<String,String>> actionList=assAdminMapper.getAllAssAction();

        Map<String,String> map=actionList.get(actionList.size()-1);
        Integer actionId=Integer.valueOf(String.valueOf(map.get("ass_id")))+1;

        addAction.setActionId(actionId.toString());

        addAction.setDate(addAction.getDate()+" "+addAction.getDate2());
        Integer i=assAdminMapper.insertIntoAction(addAction);

        return Result.success("添加成功",i);
    }

    @Override
    public Result deleteAssImageById(String assId) {
        Integer i=assAdminMapper.deleteAssImageById(assId);
        return Result.success("请重新上传",0);
    }

    @Override
    public Integer insertAssImages(String filename, String Id) {
        return assAdminMapper.insertAssImages(filename,Id);
    }

    @Override
    public Result updateAssInforAdmin(AssAdminUpdateInfor assAdminUpdateInfor) {
        Integer i=assAdminMapper.updateAssInforAdmin(assAdminUpdateInfor);

        return Result.success("保存成功",i);
    }

    @Override
    public Integer insertActionImage(String actionId, String imageName) {
        return assAdminMapper.insertActionImage(actionId,imageName);
    }

    @Override
    public Result getAssActionByCond(GetAssActionCond getAssActionCond) {

        List<Map<String,String>> mapList=assAdminMapper.getAssActionByCond(getAssActionCond);
        int i=0;
        for(Map<String,String> map:mapList){
            i++;
            map.put("serid",i+"");
        }
        return Result.success("查找成功",mapList);
    }

    @Override
    public Result passUserAddAction(String stuId, String status, String action) {
        Integer i=assAdminMapper.passUserAddAction(stuId,status,action);
        if(status.equals("1")){
            return Result.success("已通过",i);
        }else if(status.equals("2")){
            return Result.success("已拒绝",i);
        }
        return Result.fail("操作异常",i);
    }

    @Override
    public Result getActionStudentBuId(String actionId) {

        List<Map<String,String>> mapList=assAdminMapper.getActionStudentBuId(actionId);
        int i=0;
        for(Map<String,String> map:mapList){
            i++;
            map.put("serid",i+"");
        }
        return Result.success("查找成功",mapList);
    }
}
